<div class="content-box"><!-- start_loai Content Box -->

    <div class="content-box-header">

        <h3>Loại sản phẩm</h3>

        <ul class="content-box-tabs">

            <li><a href="#tab1" class="default-tab">Table</a></li> <!-- href must be unique and match the id of target div -->
            <li><a href="#tab2">Forms</a></li>
        </ul>

        <div class="clear"></div>

    </div> <!-- End .content-box-header -->

    <div class="content-box-content">

        <div class="tab-content default-tab" id="tab1"> <!-- This is the target div. id must match the href of this div's tab -->
            <?php
            $display_loai=20;
            if(isset($_GET['total_loai']) && (int)$_GET['total_loai']){
                $total_loai = $_GET['total_loai'];
            }else{
                $query='SELECT COUNT(id) FROM tbl_loai';
                $res = mysql_query($query);
                $row1=mysql_fetch_array($res);
                $record = $row1[0];
                if($record > $display_loai){
                    $total_loai = ceil($record/$display_loai);
                }else{
                    $total_loai=1;
                }
            }
            $start_loai = (isset($_GET['start_loai']) && (int)$_GET['start_loai']>=0)?$_GET['start_loai']:0;
            $stt=1;
            $sql='SELECT
	   					*
		 				FROM tbl_loai

						ORDER BY id ASC LIMIT '.$start_loai.','.$display_loai.'';
            $result=mysql_query($sql);
            $num=mysql_num_rows($result);
            if($num>0)
            {
                ?>
                <table>


                    <tr  align="center">
                        <th>STT</th>

                        <th>Loại</th>
                        <th>Ảnh loại</th>
                        <th>Mã loại</th>
                        <th>Sửa/ Xóa</th>
                    </tr>

                    <?php
                    while($row=mysql_fetch_array($result))
                    {
                        ?>

                        <tr valign="middle">
                            <td><?php echo $stt++;?></td>

                            <td><a href="index.php?page=loai&act=edit&id=<?php echo $row['id'];?>"><?php  echo $row['loai'];?></a></td>
                            <td><img src="../uploads/<?php echo $row['anhl']?>" width="110" height="86" class="sp-img"></td>
                            <td><?php  echo $row['loai_id'];?></td>
                            <td>
                                <!-- Icons -->
                                <a href="index.php?page=loai&act=edit&id=<?php echo $row['id'];?>" title="Edit"><img src="resources/images/icons/edit.png" alt="Edit" /></a>
                                <a href="index.php?page=loai&act=del&id=<?php echo $row['id'];?>" title="Delete" class="del"  onclick="return confirmSubmit()"><img src="resources/images/icons/del.png" alt="Delete" /></a>
                            </td>
                        </tr>

                    <?php
                    }
                    ?>

                    <tr>
                        <?php
                        if($total_loai>1)
                        {
                            $next_loai=$start_loai + $display_loai;
                            $prev_loai=$start_loai - $display_loai;
                            $current_loai=($start_loai/$display_loai)+1;
                            ?>
                            <td colspan="9">

                                <div class="pagination" style="height:50px;">
                                    <?php
                                    //Hiển thị prev_loai
                                    if($current_loai !=1)
                                    {
                                        echo '<a href="index.php?page=chungloai&start_loai='.$prev_loai.'" title="Previous Page">&laquo; Previous</a>';
                                    }
                                    //Hiển thị phân trang trong
                                    for($i=1;$i<=$total_loai;$i++)
                                    {
                                        if($current_loai!=$i)
                                        {
                                            echo '<a href="index.php?page=chungloai&start_loai='.($display_loai*($i-1)).'"  class="number" title="1">'.$i.'</a>';
                                        }else
                                        {
                                            echo '<a class="number current">'.$i.'</a>';
                                        }
                                    }
                                    //Hiển thị next_loai
                                    if($current_loai !=$total_loai)
                                    {
                                        echo '<a href="index.php?page=chungloai&start_loai='.$next_loai.'" title="Next Page">Next &raquo;</a>';
                                    }
                                    ?>
                                </div> <!-- End .pagination -->
                                <div class="clear"></div>
                            </td>
                        <?php
                        }
                        ?>
                    </tr>

                </table>
            <?php
            }
            ?>
        </div> <!-- End #tab1 -->



    </div> <!-- End .content-box-content -->

</div> <!-- End .content-box -->
<script LANGUAGE="JavaScript">
    function confirmSubmit()
    {
        var agree=confirm("Bạn có chắc chắn xóa không?");
        if (agree)
            return true ;
        else
            return false ;
    }
</script>